package org.thread.test05.demo03;

/**
 * @author ZJL
 * @date 2025-03-12
 */
public class Account {
    /**
     * 存款
     */
    private double money;

    public Account() {

    }
    public Account(double money) {
        this.money = money;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    /**
     * 取钱
     * @param user 取款用户
     * @param money 取款金额
     */
    public synchronized void getMoney(String user,double money) {
        System.out.printf("%s：取款%.2f元\n",user,money);
        if (this.money >= money) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            this.money = this.money -  money;
            System.out.printf("剩余余额为：%.2f\n",this.money);
            return;
        }
        System.out.println("取款失败，余额不足！！！");
    }

    /**
     * 存钱
     * @param user 存款用户
     * @param money 存款金额
     */
    public void saveMoney(String user,double money) {

    }
}
